# This file is part of GPropertyGrid project. 
# The COPYRIGHT file at the top level of this repository 
# contains the full copyright notices and license terms.

from gi.repository import Gtk
from . propertygridproperty import PropertyGridProperty

class PropertyString(PropertyGridProperty):
    def __init__(self, name, 
                id=None,
                default=None,
                description=None,
                force_value=False):
                
        self._txt = Gtk.Entry()
        self._txt.connect("changed", self.on_txt_changed)
        
        super(PropertyString, self).__init__(name=name, value_widget=self._txt,
                            id=id,
                            default=default,
                            description=description,
                            force_value=force_value)

        self.set_value_text(default)
        self._txt.set_text(default)
        
    def on_txt_changed(self, wg):
        self.on_change()
        
#    def on_enter(self):
#        pass
        
    def on_leave(self):
        pass

    def on_change(self):
        if not super(PropertyString, self).on_change():
            return False
        self.value=self._txt.get_text()
        self.set_value_text(self.value)
        self.has_changed=True
        return True
        
